package si.yun.web;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.exceptions.ClientException;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.google.gson.Gson;
import io.swagger.annotations.ApiParam;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import si.yun.entity.SyBeforeUser;
import si.yun.entity.SyCourse;
import si.yun.entity.SyUserAddress;
import si.yun.entity.SyUserFeedback;
import si.yun.service.PersonalService;
import si.yun.utils.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.*;

/**
 * @program: ThinkManage
 * @description: 个人中心web层
 * @author: 崔晓晨
 * @create: 2021-10-20 14:08
 **/
@RestController
@RequestMapping("/my")
@PropertySource({"config/config.properties"})
public class PersonalController {
    //连接业务层
    @Autowired
    private PersonalService personalService;
    //获取服务器路径
    @Value("${path1}")
    private String path;
    //阿里云上传服务器
    @Autowired
    private TestAliUpload testAliUpload;
    //连接redis缓存
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * @Description  查询课程浏览记录
     * @return si.yun.utils.JsonData
     * @Date 2021/10/21 11:41
     **/
    @PostMapping("/selWatchCourse")
    public JsonData selWatchCourse(Integer userId) {
        List<Map<String, Object>> list = personalService.selWatchCourse(userId);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  批量删除观看记录
     * @return si.yun.utils.JsonData
     * @Date 2021/10/21 11:41
     **/
    @PostMapping("/delWatchCourse")
    public JsonData delWatchCourse(@RequestParam String ids){
        List<String> asList = Arrays.asList(ids.split(","));
        List<Integer> list = new ArrayList<>();
        for(String as:asList){
            Integer id = Integer.valueOf(as);
            list.add(id);
        }
        Integer del = personalService.delWatchCourse(list);
        return del!=0?JsonData.buildSuccess(del):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取订单信息
     * @return si.yun.utils.JsonData
     * @Date 2021/11/9 10:27
     **/
    @PostMapping("/selOrderInfo")
    public JsonData selOrderInfo(Integer userId, Integer orderStatus, Integer comment){
        List<Map<String, Object>> list = personalService.selOrderInfo(userId, orderStatus, comment);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取商品的订单信息
     * @return si.yun.utils.JsonData
     * @Date 2021/11/11 10:13
     **/
    @PostMapping("/getProductOrderInfo")
    public JsonData getProductOrderInfo(Integer orderId, Integer productId, Integer orderType){
        Map<String,Object> map = personalService.getProductOrderInfo(orderId,productId,orderType);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  更改订单状态
     * @return java.lang.Integer
     * @Date 2021/11/17 15:08
     **/
    @PostMapping("/updRefundStatus")
    public JsonData updRefundStatus(Integer orderId,Integer orderStatus) {
        Integer upd = personalService.updRefundStatus(orderId,orderStatus);
        return upd!=0?JsonData.buildSuccess(upd):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取优惠券的列表信息 未使用
     * @return si.yun.utils.JsonData
     * @Date 2021/11/22 15:28
     **/
    @PostMapping("/selCouponListInfo")
    public JsonData selCouponListInfo(Integer state,Integer userId){
        List<Map<String, Object>> list = personalService.selCouponListInfo(state, userId);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取优惠券的列表信息 未使用
     * @return si.yun.utils.JsonData
     * @Date 2021/11/22 15:28
     **/
    @PostMapping("/selCouponUsed")
    public JsonData selCouponUsed(Integer state,Integer userId){
        List<Map<String, Object>> list = personalService.selCouponUsed(state, userId);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取已过期的优惠券信息
     * @return si.yun.utils.JsonData
     * @Date 2021/11/22 16:47
     **/
    @PostMapping("/selExpiredCouponInfo")
    public JsonData selExpiredCouponInfo(Integer state,Integer userId){
        List<Map<String, Object>> list = personalService.selExpiredCouponInfo(state, userId);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  添加播放记录
     * @return si.yun.utils.JsonData
     * @Date 2021/11/23 11:13
     **/
    @PostMapping("/addPlayWatch")
    public JsonData addPlayWatch(Integer userId,Integer courseId,String courseName,Integer studyDate){
        System.out.println(studyDate+"===================================");
        Integer add = personalService.addPlayWatch(userId, courseId,courseName,studyDate);
        return add!=null?JsonData.buildSuccess(add):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取用户收藏记录
     * @return si.yun.utils.JsonData
     * @Date 2021/11/24 14:13
     **/
    @PostMapping("/selUserCollection")
    public JsonData selUserCollection(Integer userId) {
        List<Map<String, Object>> list = personalService.selUserCollection(userId);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取用户购买的课程信息
     * @return si.yun.utils.JsonData
     * @Date 2021/11/25 9:01
     **/
    @PostMapping("/selBuyCourse")
    public JsonData selBuyCourse(Integer userId) {
        List<Map<String, Object>> list = personalService.selBuyCourse(userId);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取当前用户是否认证过创作者
     * @return si.yun.utils.JsonData
     * @Date 2021/11/25 9:32
     **/
    @PostMapping("/selApplyRecord")
    public JsonData selApplyRecord(Integer userId) {
        Map<String,Object> map = personalService.selApplyRecord(userId);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    @PostMapping("/uploadCourseImg")
    public JsonData uploadImg(@RequestParam("file") MultipartFile file) throws IllegalStateException, IOException {
        String newName = uploadFile(file);
        System.out.println(newName+"=================================================");
        Map<String,Object> map = new HashMap<>();
        map.put("newName",newName);
        map.put("path",path);
        return map != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器异常！请耐心等待修复！");
    }
    public String  uploadFile(@RequestParam MultipartFile files) throws IllegalStateException, IOException {
        //上传到服务器
        String newName = testAliUpload.upload(files);
        return newName;
    }
    /**
     * @Description  获取课程的分类
     * @return si.yun.utils.JsonData
     * @Date 2021/11/25 15:39
     **/
    @GetMapping("/selCourseClass")
    public JsonData selCourseClass(){
        List<Map<String, Object>> list = personalService.selCourseClass();
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description 添加课程 (或者保存为草稿状态)
     * @return si.yun.utils.JsonData
     * @Date 2021/11/25 16:50
     **/
    @PostMapping("/addCourseInfo")
    public JsonData addCourseInfo(Integer userId,Integer classId,
                                  String courseName,String courseIntro,
                                  Integer courseCstatus,String coursePrimary,
                                  String url,String courseUrl){
        SyCourse course = new SyCourse();
        course.setClassId(classId);
        course.setUserId(userId);
        course.setCourseName(courseName);
        course.setCourseIntro(courseIntro);
        course.setCourseCstatus(courseCstatus);
        course.setCoursePrimary(coursePrimary);
        course.setUrl(url);
        course.setCourseUrl(courseUrl);
        Integer add = personalService.addCourseInfo(course);
        return add!=0?JsonData.buildSuccess(add):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取个人创作的课程
     * @return si.yun.utils.JsonData
     * @Date 2021/11/26 10:12
     **/
    @PostMapping("/selCreationCourse")
    public JsonData selCreationCourse(Integer userId){
        List<Map<String, Object>> list = personalService.selCreationCourse(userId);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  修改课程信息
     * @return si.yun.utils.JsonData
     * @Date 2021/11/26 14:06
     **/
    @PostMapping("/updCourseInfo")
    public JsonData updCourseInfo(@RequestParam Map<String,Object> map){
        Integer updCourseInfo = personalService.updCourseInfo(map);
        return updCourseInfo!=0?JsonData.buildSuccess(updCourseInfo):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取认证信息
     * @return si.yun.utils.JsonData
     * @Date 2021/11/29 18:51
     **/
    @PostMapping("/selReviewInfo")
    public JsonData selReviewInfo(Integer userId){
        Map<String, Object> map = personalService.selReviewInfo(userId);
        return JsonData.buildSuccess(map);
    }
    /**
     * @Description  添加审核创作者
     * @return si.yun.utils.JsonData 
     * @Date 2021/12/2 8:53
     **/
    @PostMapping("/addCreateUser")
    public JsonData addCreateUser(@RequestParam Map<String,Object> map){
        Integer integer = personalService.addCreateUser(map);
        return integer!=0?JsonData.buildSuccess(integer):JsonData.buildError("服务器错误");
    }
    /**
     * 获取用户的地址信息
     * @param userId 用户id
     * @return
     */
    @PostMapping("/getUserAddressIsDefault")
    public JsonData getUserAddressIsDefault(Integer userId){
        Map<String, Object> map = personalService.getUserAddressIsDefault(userId);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * 向用户发送验证码
     * @param phone 用户手机号
     * @return
     */
    @PostMapping("/sendCode")
    public JsonData sendCode(String phone){
        String code = GetRandomUtil.randomCode();
        try {
            //向此手机号发送验证码
            SendMessage.sendSms(phone,code);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return code!=null?JsonData.buildSuccess(code):JsonData.buildError("服务端错误");
    }
    /**
     * 修改用户的手机号
     * @param userId
     * @param phone
     * @return
     */
    @PostMapping("/setUserPhone")
    public JsonData setUserPhone(Integer userId,String phone){
        Integer i = personalService.setUserPhone(userId,phone);
        return i > 0 ? JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }
    /**
     * 修改用户的密码
     * @param userId
     * @param password
     * @return
     */
    @PostMapping("/setUserPassword")
    public JsonData setUserPassword(Integer userId,String password){
        Integer i = personalService.setUserPassword(userId,password);
        return i > 0 ? JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }
    /**
     * 查看用户的所有收货地址
     * @param userId
     * @return
     */
    @PostMapping("/getUserAddress")
    public JsonData getUserAddress(Integer userId){
        List<Map<String,Object>> list = personalService.getUserAddress(userId);
        return list != null ? JsonData.buildSuccess(list):JsonData.buildError("服务端错误");
    }
    /**
     * 修改用户当前地址是否为默认状态
     * @param userId
     * @param addressId
     * @param isDefault
     * @return
     */
    @PostMapping("/setDefaultAddress")
    public JsonData setDefaultAddress(Integer userId,Integer addressId,String isDefault){
        Integer i = personalService.setDefaultAddress(userId, addressId, isDefault);
        return i > 0 ? JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }
    /**
     * 获取省市区
     * @param id
     * @return
     */
    @PostMapping("/getRegion")
    public JsonData getRegion(Integer id){
        List<Map<String,Object>> list = personalService.getRegion(id);
        return list != null ? JsonData.buildSuccess(list):JsonData.buildError("服务端错误");
    }
    /**
     * 添加用户地址
     * @param userAddress
     * @return
     */
    @PostMapping("/addUserAddress")
    public JsonData addUserAddress(SyUserAddress userAddress){
        Integer i = personalService.addUserAddress(userAddress);
        setDefaultAddress(userAddress.getUserId(),userAddress.getAddressId(),String.valueOf(userAddress.getIsDefault()));
        return i > 0 ? JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }
    /**
     * 通过id查看收货地址
     * @param addressId
     * @return
     */
    @PostMapping("/getUserAddres")
    public JsonData getUserAddres(Integer addressId){
        Map<String,Object> map = personalService.getUserAddres(addressId);
        return map != null ? JsonData.buildSuccess(map):JsonData.buildError("服务端错误");
    }
    /**
     * 修改收货地址
     * @param userAddress
     * @return
     */
    @PostMapping("/setUserAddress")
    public JsonData setUserAddress(SyUserAddress userAddress){
        Integer i = personalService.setUserAddress(userAddress);
        setDefaultAddress(userAddress.getUserId(),userAddress.getAddressId(),String.valueOf(userAddress.getIsDefault()));
        return i > 0 ? JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }
    /**
     * 通过id删除收货地址
     * @param addressId
     * @return
     */
    @PostMapping("/removeUserAddress")
    public JsonData removeUserAddress(Integer addressId){
        Integer i = personalService.removeUserAddress(addressId);
        return i > 0 ? JsonData.buildSuccess(i):JsonData.buildError("服务端错误");
    }
    /**
     * 通过名称删除图片
     * @param path
     */
    @PostMapping("/removeUploadImg")
    public void removeUploadImg(String path){
        testAliUpload.delete(path);
    }

    /**
     * 添加用户意见反馈
     * @param userFeedback
     */
    @PostMapping("/addUserFeedback")
    public JsonData addUserFeedback(SyUserFeedback userFeedback){
        //设置为待审核状态
        userFeedback.setFeedbackStatus(3);
        try {
            //获取当前时间
            userFeedback.setCreateDate(Utils.getDateToTimeString(new Date()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Integer i = personalService.addUserFeedback(userFeedback);
        return i > 0 ? JsonData.buildSuccess(userFeedback):JsonData.buildError("服务端错误");
    }
    /**
     * @return si.yun.utils.JsonData
     * @Description 获取个人微圈
     * @Date 2021/11/26 10:12
     **/
    @PostMapping("/selMicroCircleOwnData")
    public JsonData selMicroCircleOwnData(Integer userId) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> m = personalService.selMicroCircleOwnData(userId);
        map.put("path", path);
        map.put("data", m);
        return map != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取系统最新通知信息
     * @return si.yun.utils.JsonData
     * @Date 2021/12/2 10:42
     **/
    @PostMapping("/selNoteNewInfo")
    public JsonData selNoteNewInfo(Integer userId){
        Map<String, Object> map = personalService.selNoteNewInfo(userId);
        if(map==null){
            return JsonData.buildSuccess("暂无通知");
        }else{
            map.put("trueName","系统通知");
            return map != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器错误");
        }
    }
    /**
     * @Description  获取所有的系统通知
     * @return si.yun.utils.JsonData
     * @Date 2021/12/2 12:01
     **/
    @PostMapping("/selAllNotesInfo")
    public JsonData selAllNotesInfo(Integer userId){
        List<Map<String, Object>> list = personalService.selAllNotesInfo(userId);
        return list != null ? JsonData.buildSuccess(list) : JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取未读消息数量
     * @return si.yun.utils.JsonData
     * @Date 2021/12/2 16:12
     **/
    @PostMapping("/selNoteNum")
    public JsonData selNoteNum(Integer userId){
        Map<String, Object> map = personalService.selNoteNum(userId);
        return map != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器错误");
    }
    /**
     * @Description  批量更新消息状态信息
     * @return si.yun.utils.JsonData 
     * @Date 2021/12/2 16:53
     **/
    @PostMapping("/updNoteStatus")
    public JsonData updNoteStatus(Integer id){
        Integer updNoteStatus = personalService.updNoteStatus(id);
        return updNoteStatus != null ? JsonData.buildSuccess(updNoteStatus) : JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取用户学习时长以及消费记录
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @Date 2021/12/14 9:38
     **/
    @PostMapping("/selStudyMoney")
    public JsonData selStudyMoney(Integer userId) {
        Map<String, Object> map = personalService.selStudyMoney(userId);
        return  JsonData.buildSuccess(map);
    }
    /**
     * 修改初次注册的用户的手机号
     * @param userId
     * @param phone
     * @return
     */
    @PostMapping("/setRegisterUserPhone")
    public JsonData setRegisterUserPhone(Integer userId,String phone){
        SyBeforeUser userInfo = personalService.getUserInfo(userId);
        Integer i = 0;
        //若手机号为空，则是初次注册用户
        if (userInfo.getPhone()==null){
            i = personalService.setRegisterUserPhone(userId, phone);
            if (i > 0) {
                userInfo = personalService.getUserInfo(userId);
                if(userInfo.getAvatarUrl()!=null && userInfo.getAvatarUrl().indexOf("http") == -1){
                    userInfo.setAvatarUrl(path+userInfo.getAvatarUrl());
                }
            }
        }
        return userInfo!=null ? JsonData.buildSuccess(userInfo):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取优惠券的详细信息
     * @return si.yun.utils.JsonData
     * @Date 2021/12/15 19:34
     **/
    @PostMapping("/selCouponInfo")
    public JsonData selCouponInfo(Integer orderId,Integer userId){
        Map<String, Object> num = personalService.selOrderCouponNum(orderId, userId);
        Long couponUsedNum = (Long) num.get("couponUsedNum");
        if(couponUsedNum!=0){
            Map<String,Object> map = personalService.selCouponInfo(orderId,userId);
            map.put("couponUsedNum",couponUsedNum);
            return map!=null ? JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
        }else{
            return num!=null ? JsonData.buildSuccess(num):JsonData.buildError("服务器错误");
        }
    }
    /**
     * 判断此手机号是否被注册
     * @param phone
     * @return
     */
    @PostMapping("getPhoneExist")
    public  JsonData getPhoneExist(String phone){
        Integer i = personalService.getPhoneExist(phone);
        return i == 0 ? JsonData.buildSuccess(i):JsonData.buildError("服务器错误");
    }
    /**
     * 通过用户上传身份证证件照片获取信息修改用户的实名认证
     * @param userId
     * @param frontPath
     * @param backPath
     * @return
     */
    @PostMapping("/setUserRealByImg")
    public JsonData setUserRealByImg(Integer userId,String frontPath,String backPath){
        SyBeforeUser user = personalService.setUserRealByImg(userId, frontPath, backPath);
        if(user != null){
            if(user.getAvatarUrl()!=null && user.getAvatarUrl().indexOf("http") == -1){
                user.setAvatarUrl(path+user.getAvatarUrl());
            }
        }
        return JsonData.buildSuccess(user);
    }
    /**
     * @Description  更新最新的APP版本
     * @return si.yun.utils.JsonData 
     * @Date 2021/12/27 13:29
     **/
    @GetMapping("/selAppVersion")
    public JsonData selAppVersion(){
        Map<String, Object> mapVersion = personalService.selAppVersion();
        return mapVersion!=null ? JsonData.buildSuccess(mapVersion):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  删除草稿视频
     * @return si.yun.utils.JsonData
     * @Date 2021/12/28 9:05
     **/
    @PostMapping("/delCourseNutton")
    public JsonData delCourseNutton(Integer courseId){
        Integer del = personalService.delCourseNutton(courseId);
        return del!=0 ? JsonData.buildSuccess(del):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  查询商品的详情信息
     * @return si.yun.utils.JsonData 
     * @Date 2022/1/4 10:31
     **/
    @PostMapping("/selProductInfoes")
    public JsonData selProductInfoes(Integer productId){
        Map<String, Object> map = personalService.selProductInfoes(productId);
        return map!=null ? JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  查询指定分类下的商品
     * @return si.yun.utils.JsonData
     * @Date 2022/1/5 14:04
     **/
    @PostMapping("/selClassProductInfoes")
    public JsonData selClassProductInfoes(Integer categoryId,Integer productId){
        List<Map<String, Object>> list = personalService.selClassProductInfoes(categoryId, productId);
        return list!=null ? JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取评论的数量
     * @return si.yun.utils.JsonData
     * @Date 2022/1/6 11:27
     **/
    @PostMapping("/selCommentProductNum")
    public JsonData selCommentProductNum(Integer productId){
        Map<String, Integer> stringIntegerMap = personalService.selCommentProductNum(productId);
        return stringIntegerMap!=null ? JsonData.buildSuccess(stringIntegerMap):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取商品下的评论
     * @return si.yun.utils.JsonData
     * @Date 2022/1/6 16:55
     **/
    @PostMapping("/selproductComments")
    public JsonData selCourseComments(Integer productId,Integer userId){
        List<Map<String, Object>> list = personalService.selproductComments(productId,userId);
        return JsonData.buildSuccess(list);
    }
    /**
     * @Description  点赞评论
     * @return si.yun.utils.JsonData
     * @Date 2022/1/6 19:55
     **/
    @PostMapping("/addProductCommentLike")
    public JsonData addProductCommentLike(Integer commentId,Integer userId,Integer productId){
        Integer add = personalService.addProductCommentLike(commentId, userId, productId);
        return add!=0?JsonData.buildSuccess(add):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  取消点赞评论
     * @return si.yun.utils.JsonData
     * @Date 2022/1/6 19:55
     **/
    @PostMapping("/delProductCommentLike")
    public JsonData delProductCommentLike(Integer commentId,Integer userId,Integer productId){
        //取消评论
        Integer delCommentLike = personalService.delProductCommentLike(commentId, userId, productId);
        return delCommentLike!=0?JsonData.buildSuccess(delCommentLike):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  添加留言
     * @return si.yun.utils.JsonData
     * @Date 2022/1/7 9:09
     **/
    @PostMapping("/addProductCommentInfo")
    public JsonData addProductCommentInfo(Integer userId,Integer productId,String content){
        Integer add = personalService.addProductCommentInfo(userId,productId,content);
        return add!=0?JsonData.buildSuccess(add):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  删除个人评论 更改状态为删除
     * @return si.yun.utils.JsonData
     * @Date 2022/1/7 9:09
     **/
    @PostMapping("/updProductCommentStatusDel")
    public JsonData updProductCommentStatusDel(Integer commentId,Integer userId,Integer productId){
        //删除个人评论 更改状态为删除
        Integer upd = personalService.updProductCommentStatusDel(commentId,userId,productId);
        return upd!=0?JsonData.buildSuccess(upd):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  判断商品是否收藏
     * @return si.yun.utils.JsonData
     * @Date 2022/1/7 9:56
     **/
    @PostMapping("/selProductColCourseIF")
    public JsonData selProductColCourseIF(Integer userId, Integer productId){
        Integer sel = personalService.selProductColCourseIF(userId, productId);
        return JsonData.buildSuccess(sel);
    }
    /**
     * @Description  收藏商品
     * @return si.yun.utils.JsonData
     * @Date 2022/1/7 10:33
     **/
    @PostMapping("/addProductColCourseInfo")
    public JsonData addProductColCourseInfo(Integer userId,Integer productId){
        //删除个人评论 更改状态为删除
        Integer add = personalService.addProductColCourseInfo(userId,productId);
        return add!=0?JsonData.buildSuccess(add):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  取消收藏
     * @return si.yun.utils.JsonData
     * @Date 2022/1/7 10:33
     **/
    @PostMapping("/delProductColCourseInfo")
    public JsonData delProductColCourseInfo(Integer userId,Integer productId){
        //删除个人评论 更改状态为删除
        Integer upd = personalService.delProductColCourseInfo(userId,productId);
        return upd!=0?JsonData.buildSuccess(upd):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取购物车的商品数量
     * @return si.yun.utils.JsonData
     * @Date 2022/1/7 15:36
     **/
    @PostMapping("/selShoppingCart")
    public JsonData selShoppingCart(Integer userId){
        Map<String, Object> map = personalService.selShoppingCart(userId);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取购物车的详细信息
     * @return si.yun.utils.JsonData
     * @Date 2022/1/10 9:44
     **/
    @PostMapping("/selShopChartInfo")
    public JsonData selShopChartInfo(Integer userId){
        List<Map<String, Object>> list = personalService.selShopChartInfo(userId);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  更新购物车的商品数量
     * @return si.yun.utils.JsonData
     * @Date 2022/1/10 11:28
     **/
    @PostMapping("/updShopChartNum")
    public JsonData updShopChartNum(Integer shoppingCartId, Integer productNum){
        Integer updShopChartNum = personalService.updShopChartNum(shoppingCartId, productNum);
        return updShopChartNum!=0?JsonData.buildSuccess(updShopChartNum):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  批量删除购物车
     * @return si.yun.utils.JsonData 
     * @Date 2022/1/10 16:44
     **/
    @PostMapping("/deleteShoppingCart")
    public JsonData deleteShoppingCart(@RequestParam String ids){
        List<String> asList = Arrays.asList(ids.split(","));
        List<Integer> list = new ArrayList<>();
        for(String as:asList){
            Integer id = Integer.valueOf(as);
            list.add(id);
        }
        Integer del = personalService.deleteShoppingCart(list);
        return del!=0?JsonData.buildSuccess(del):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  添加购物车
     * @return si.yun.utils.JsonData
     * @Date 2022/1/10 18:49
     **/
    @PostMapping("/addShoppingCart")
    public JsonData addShoppingCart(Integer userId,Integer productId){
        //判断当前用户是否添加指定商品到购物车
        Integer shopNum = personalService.selShopProduct(userId,productId);
        Integer result;
        if(shopNum!=0){
            result = 400;
        }else{
            result = personalService.addShoppingCart(userId, productId);
        }
        return result!=0?JsonData.buildSuccess(result):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取微商城数据
     * @return si.yun.utils.JsonData
     * @Date 2021/12/28 9:05
     **/
    @GetMapping("/selMicroMall")
    public JsonData selMicroMall(){
        //List<Map<String, Object>> ForumClass = microCircleService.selForumClass();
        //redis缓存中获取
        ValueOperations<String,String> vo = redisTemplate.opsForValue();
        String value = vo.get("selMicroMall");
        Gson gson = new Gson();
        List<Map<String , Object>> ForumClass = gson.fromJson(value, List.class);
        return ForumClass!=null?JsonData.buildSuccess(ForumClass):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取购物车下对应的商品
     * @return si.yun.utils.JsonData
     * @Date 2022/1/14 16:50
     **/
    @PostMapping("/selshopProductId")
    public JsonData selshopProductId(@RequestParam String ids){
        List<String> asList = Arrays.asList(ids.split(","));
        Map<String,List> map = new HashMap<>();
        List<Integer> proList = new ArrayList<>();
        List<Integer> shopList = new ArrayList<>();
        for(String as:asList){
            Integer shoppingCartId = Integer.valueOf(as);
            Integer info = personalService.selshopProductId(shoppingCartId);
            proList.add(info);
            shopList.add(shoppingCartId);
        }
        map.put("proList",proList);
        map.put("shopList",shopList);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }
    /**
     * @Description  获取商品订单所需要的信息
     * @return si.yun.utils.JsonData
     * @Date 2022/1/14 16:28
     **/
    @PostMapping("/selOrderProInfo")
    public JsonData selOrderProInfo(Integer productId,Integer shoppingCartId){
        Map<String, Object> map = personalService.selOrderProInfo(productId,shoppingCartId);
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器错误");
    }

}
